#ifndef COMMON_H_
#define COMMON_H_

#include <stdint.h>  // Use fixed-width integers for MISRA compliance (Rule 6.3)

// MISRA C-2012 Rule 21.6: The Standard Library input/output functions
// <stdio.h> shall not be used.
// Deviation: Required for basic I/O for demonstration purposes in this example.
#include <stdio.h>

// MISRA C-2012 Rule 21.3: The memory management functions of <stdlib.h>
// shall not be used.
// Deviation: cJSON library and dynamic message creation fundamentally require
// dynamic memory allocation (malloc, free). In a strict MISRA environment,
// a static memory pool would be required, significantly increasing complexity.
#include <stdlib.h>

#include <string.h>

// Define constants to avoid magic numbers (MISRA Rule 2.1, 17.7)
#define SERVER_PORT 8888
#define MAX_BUFFER_SIZE 4096
#define RPC_JSON_VERSION "2.0"
#define MAX_CONNECTIONS_QUEUE 5 // <-- THIS LINE WAS ADDED

// Use typedef for struct definitions as per Google C++ Style Guide.
// This struct demonstrates passing complex data types.
typedef struct {
  char name[64];
  int32_t age;
  char city[64];
} UserProfile;

// RPC Error codes, following the JSON-RPC 2.0 specification.
// Using an enum improves type safety and readability (MISRA Rule 10.3).
typedef enum {
  RPC_SUCCESS = 0,
  RPC_PARSE_ERROR = -32700,
  RPC_INVALID_REQUEST = -32600,
  RPC_METHOD_NOT_FOUND = -32601,
  RPC_INVALID_PARAMS = -32602,
  RPC_INTERNAL_ERROR = -32603
} RpcErrorCode;

#endif  // COMMON_H_

